package dimension.starry.constants;

import dimension.starry.utils.RandomUtil;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public enum WeaponAttribute {

    SMALL_DAMAGE("small_damage", false, 100, List.of(28d, 42d, 47d), List.of(8d, 12d, 13d), List.of(7d, 7d, 8d, 9d),
        List.of(11d, 12d, 14d, 16d), List.of(14d, 16d, 18d, 19d)
    ),
    BIG_DAMAGE("big_damage", true, 100, List.of(0.052, 0.063, 0.07), List.of(0.015, 0.018, 0.02),
        List.of(0.025, 0.028, 0.032, 0.035),
        List.of(0.033, 0.037, 0.042, 0.047), List.of(0.041, 0.047, 0.053, 0.058)
    ),
    SMALL_HEALTH("small_health", false, 100, List.of(430d, 645d, 717d), List.of(122d, 183d, 203d),
        List.of(100d, 115d, 129d, 143d),
        List.of(167d, 191d, 215d, 239d), List.of(209d, 239d, 269d, 299d)
    ),
    BIG_HEALTH("big_health", true, 100, List.of(0.052, 0.063, 0.07), List.of(0.015, 0.018, 0.02),
        List.of(0.025, 0.028, 0.032, 0.035),
        List.of(0.033, 0.037, 0.042, 0.047), List.of(0.041, 0.047, 0.053, 0.058)
    ),
    SMALL_DEFENSE("small_defense", false, 100, null, null, List.of(8d, 9d, 10d, 11d), List.of(13d, 15d, 17d, 19d),
        List.of(16d, 19d, 21d, 23d)
    ),
    BIG_DEFENSE("big_defense", true, 100, List.of(0.036, 0.079, 0.087), List.of(0.019, 0.022, 0.025),
        List.of(0.031, 0.035, 0.039, 0.044),
        List.of(0.041, 0.047, 0.053, 0.058), List.of(0.051, 0.058, 0.066, 0.073)
    ),
    CRITICAL_CHANCE("critical_chance", true, 40, List.of(0.035, 0.042, 0.047), List.of(0.01, 0.012, 0.013),
        List.of(0.016, 0.019, 0.021, 0.023),
        List.of(0.022, 0.025, 0.028, 0.031), List.of(0.027, 0.031, 0.035, 0.039)
    ),
    CRITICAL_DAMAGE("critical_damage", true, 40, List.of(0.07, 0.084, 0.094), List.of(0.02, 0.024, 0.026),
        List.of(0.033, 0.037, 0.042, 0.047),
        List.of(0.044, 0.05, 0.056, 0.062), List.of(0.054, 0.062, 0.07, 0.078)
    ),
    SPEED("speed", false, 20, List.of(2d, 3d, 4d), List.of(3d, 3.25, 4.2), List.of(1d, 1d, 1d, 1d),
        List.of(1d, 1d, 1d, 2d),
        List.of(2d, 2d, 2d, 2.6d)
    ),
    ;

    private final String name;
    private final boolean isPercentage;
    private final int randomWeight;
    private final Text translationTag;
    private final List<Double> startAttrs;
    private final List<Double> perLevelAdds;
    private final List<Double> lowerAttrs;
    private final List<Double> mediumAttrs;
    private final List<Double> highAttrs;

    WeaponAttribute(
        String name, boolean isPercentage, int randomWeight, List<Double> startAttrs, List<Double> perLevelAdds,
        List<Double> lowerAttrs,
        List<Double> mediumAttrs, List<Double> highAttrs
    ) {
        this.name = name;
        this.isPercentage = isPercentage;
        this.randomWeight = randomWeight;
        this.translationTag = Text.translatable("starry_dimension.weapon_attribute." + name);
        this.startAttrs = startAttrs;
        this.perLevelAdds = perLevelAdds;
        this.lowerAttrs = lowerAttrs;
        this.mediumAttrs = mediumAttrs;
        this.highAttrs = highAttrs;
    }

    @Nullable
    public static WeaponAttribute getByName(String name) {
        for (WeaponAttribute weaponAttribute : WeaponAttribute.values()) {
            if (weaponAttribute.name.equals(name)) {
                return weaponAttribute;
            }
        }
        return null;
    }

    public String getName() {
        return name;
    }

    public Text getTranslationTag() {
        return translationTag;
    }

    public double getRandomAttrsByQuality(ItemQuality quality) {
        int randomInt = RandomUtil.randomInt(0, 4);
        if (ItemQuality.EXCELLENT.equals(quality)) {
            return lowerAttrs.get(randomInt);
        } else if (ItemQuality.FINE.equals(quality)) {
            return mediumAttrs.get(randomInt);
        } else if (ItemQuality.PERFECT.equals(quality)) {
            return highAttrs.get(randomInt);
        }
        return lowerAttrs.get(randomInt);
    }

    public List<Double> getStartAttrs() {
        return startAttrs;
    }

    public List<Double> getPerLevelAdds() {
        return perLevelAdds;
    }

    public boolean isPercentage() {
        return isPercentage;
    }

    public int getRandomWeight() {
        return randomWeight;
    }
}
